package cn.dhnep.demo.service.impl;

import cn.dhnep.demo.mapper.DeBangMapper;
import cn.dhnep.demo.pojo.entity.DbOrder;
import cn.dhnep.demo.pojo.entity.Result;
import cn.dhnep.demo.service.DeBangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 邱文彬
 * @Date 2021/12/2 14:46
 * @Version 1.0
 */


@Service
public class DeBangServiceImpl implements DeBangService {

    @Autowired
    private DeBangMapper deBangMapper;

    @Override
    public List<DbOrder> getAll(long page, long record) {


        List<DbOrder> dbOrderList = deBangMapper.getAll();
        List<DbOrder> dbOrders = new ArrayList<>();
        long num = page * record;//10
        long num2 = (page - 1) * record;//0
        int num3 = 0;
        int num4 = 0;



            for (DbOrder dbOrder : dbOrderList) {
                if (num3 == num2) {
                    if (num2 < num) {
                        num2++;
                        dbOrders.add(num4++, dbOrder);
                    }
                }
                num3++;
            }
            return dbOrders;



    }


    @Override
    public Result getOrderDataByPhone(String senderMobile) {
        List<DbOrder> dbOrder = deBangMapper.getOrderDataByPhone(senderMobile);
        if(dbOrder != null){
            return new Result(0,"操作成功",dbOrder);
        }else{
            return new Result(0,"ID错误,查询失败",null);
        }


    }

    @Override
    public Result getOrderDataById(String id) {
        DbOrder dbOrder = deBangMapper.getOrderDataById(id);
        if(dbOrder != null){
            return new Result(0,"操作成功",dbOrder);
        }else{
            return new Result(0,"ID错误,查询失败",null);
        }
    }
}
